package offerbook;

import java.util.Stack;

/**
 * @date 2020/3/7 23:13
 */
public class Code07_StackToQueue {
    //pushStack栈顶始终保持着最后入栈元素
    Stack<Integer> pushStack = new Stack<Integer>();
    //popStack栈顶始终保持着最先入栈元素
    Stack<Integer> popStack = new Stack<Integer>();

    //offer
    public void offer(int node) {
        pushStack.push(node);
    }

    //poll
    public int poll() {
        if(isEmpty()) throw new RuntimeException("empty");
        dao();
        return popStack.pop();
    }

    public void dao(){
        if(!popStack.isEmpty()) return;
        while (!pushStack.isEmpty()){
            popStack.push(pushStack.pop());
        }
    }
    public boolean isEmpty(){
        return pushStack.isEmpty() && popStack.isEmpty();
    }
}
